/**
 * zmn 花名册模块-员工合同信息
 * @author tanghongjun
 * @since 2020-05-14 10:56:45
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;
    var laydate = layui.laydate;

    if(json.staffContract.fristContractTime != null){
        laydate.render({elem: "#fristContractTime", type: "date", value: new Date(json.staffContract.fristContractTime)});
    }else{
        laydate.render({elem: "#fristContractTime", type: "date"});
    }

    if(json.staffContract.fristContractEndTime != null){
        laydate.render({elem: "#fristContractEndTime", type: "date", value: new Date(json.staffContract.fristContractEndTime)});
    }else{
        laydate.render({elem: "#fristContractEndTime", type: "date"});
    }

    if(json.staffContract.contractTimeNow != null){
        laydate.render({elem: "#contractTimeNow", type: "date", value: new Date(json.staffContract.contractTimeNow)});
    }else{
        laydate.render({elem: "#contractTimeNow", type: "date"});
    }

    if(json.staffContract.contractEndTimeNow != null){
        laydate.render({elem: "#contractEndTimeNow", type: "date", value: new Date(json.staffContract.contractEndTimeNow)});
    }else{
        laydate.render({elem: "#contractEndTimeNow", type: "date"});
    }

    form.render(null, "zmn-form");

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        var data = obj.field;
        var url = "/staff/staffcontract/addEdit.action";

        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success:function(result) {
                if(result.status == 200) {
                    //提示信息为弹出框形式
                    parent.layer.open({
                        title:"温馨提示",
                        content: json.message.replace("【","【<span style='color:red;'>").replace("】","</span>】")
                    });
                } else {
                    layer.msg(result.message, {"icon": 2});
                }


            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
            }
        })
        return false;
    });
    //对外暴露的接口
    exports('plat_staffcontract_detail', {});
});
